package com.base.common.persistent.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.base.common.persistent.model.Terminal;
import com.cjy.common.annotation.MyBatisRepository;

/**
 * 设备信息dao
 * 
 * @author kat.luhongkai
 * 
 */
@MyBatisRepository
public interface TerminalMapper {

	/**
	 * 添加设备信息
	 * 
	 * @param terminal
	 * @return
	 */
	public int addTerminal(Terminal terminal);

	/**
	 * 根据手机号查询有效的设备信息
	 * 
	 * @param phone
	 * @return
	 */
	public List<Terminal> queryTerminalByPhoneRegisted(
			@Param(value = "phone") String phone, @Param(value = "bid") int bid);

	/**
	 * 根据设备码查询不是注销状态的设备信息
	 * 
	 * @param code
	 * @param bid
	 * @return
	 */
	public List<Terminal> queryTerminalByCodeNotCancel(
			@Param(value = "code") String code, @Param(value = "bid") int bid);

	/**
	 * 根据手机号以及设备码查询未开通状态的设备信息
	 * 
	 * @param code
	 * @param phone
	 * @param bid
	 * @return
	 */
	public List<Terminal> queryTerminalByCodeAndPhoneNotRegisted(
			@Param(value = "code") String code,
			@Param(value = "phone") String phone, @Param(value = "bid") int bid);

	/**
	 * 根据手机号以及设备码查询有效状态的设备信息
	 * 
	 * @param code
	 * @param phone
	 * @return
	 */

	/**
	 * 根据id进行更新验证码
	 * 
	 * @param terminal
	 * @return
	 */
	public int updateCaptchaByCodeAndPhone(Terminal terminal);

	/**
	 * 根据id进行更新设备状态
	 * 
	 * @param terminal
	 * @return
	 */
	public int updateStatusByCodeAndPhone(Terminal terminal);

	public List<Terminal> queryTerminalByCodesAndPhoneNotRegisted(
			@Param(value = "openId") String openId,
			@Param(value = "appleId") String appleId,
			@Param(value = "code") String code,
			@Param(value = "phone") String phone, @Param(value = "bid") int bid);

	/**
	 * 根据微信是否已经注册
	 * 
	 * @param openId
	 * @return
	 */
	public List<Terminal> queryTerminalByOpenIdNotCancel(
			@Param(value = "openId") String openId);

	/**
	 * 查询微信号和手机是否已经注册
	 * 
	 * @param trim
	 * @param trim2
	 * @return
	 */
	public List<Terminal> queryTerminalByCodesOrPhoneNotRegisted(
			@Param(value = "openId") String openId,
			@Param(value = "appleId") String appleId,
			@Param(value = "code") String code,
			@Param(value = "phone") String phone, @Param(value = "bid") int bid);

	/**
	 * 根据openId查询有效的微信信息
	 * 
	 * @param openId
	 * @return
	 */
	public List<Terminal> queryTerminalByCodesRegisted(
			@Param(value = "openId") String openId,
			@Param(value = "appleId") String appleId,
			@Param(value = "code") String code, @Param(value = "bid") int bid);

	/**
	 * 根据设备id查询设备信息
	 * 
	 * @param id
	 * @return
	 */
	public List<Terminal> queryTerminalById(@Param(value = "id") int id);

	/**
	 * 根据openId和手机号码更新验证码
	 * 
	 * @param terminal
	 * @return
	 */
	public int updateCaptchaByOpenIdAndPhone(Terminal terminal);

	/**
	 * 根据openId和手机号更新设备状态
	 * 
	 * @param terminal
	 * @return
	 */
	public int updateStatusByOpenIdAndPhone(Terminal terminal);

	/**
	 * 根据设备码更新clientId
	 * 
	 * @param code
	 * @param clientId
	 * @param bid
	 * @return
	 */
	public int updateClientIdByCode(@Param(value = "code") String code,
			@Param(value = "clientId") String clientId,
			@Param(value = "bid") int bid);

	public int updateTerminalById(Terminal terminal);

	/**
	 * 
	 * 根据设备码和APP类型查询的设备信息
	 * 
	 * @param code
	 * @param bid
	 * @return
	 */
	public Terminal queryRegistedTerminalByCodeAndBid(
			@Param(value = "code") String code, @Param(value = "bid") int bid);
}
